from leancloud import Object
from leancloud import File
from leancloud import Query
from leancloud import LeanCloudError
from leancloud import User
from flask import request
from datetime import datetime
import time
import os
from werkzeug.utils import secure_filename
import json

class GainData():
    def gainAvatar(self,name):
        url = None
        try:
            mUsers = Query(User).equal_to("username", name).descending(
                    'createdAt').find()
            count = len(mUsers)
            if (count > 0):
                fil = mUsers[0].get('avatar')
                if (fil != None):
                    url = fil.url
                else:
                    url = None
        except LeanCloudError, e:
            url = None
            if e.code == 101:
                mUsers = []
            else:
                raise e
        return url
